 #ifdef __unix__
#include <sys/types.h>
 
#include <unistd.h>
#include<sys/stat.h>
#include<fcntl.h> 
#include <linux/param.h>
 
 
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
 
#include <time.h>
#include <sys/time.h>
 
#include <fstream>
#include <sstream>
#include <istream>
#include <iterator>
	
#include <vector>
#include <string>
 
#include <iostream>		
 
	
 
#endif
 
 using namespace std;
 
 
 
	
 std::string time2string(time_t nt)
 {
 	tm time_in;
	
	
	localtime_r(&nt, &time_in);
	
	tm *tm_ = &time_in;						  // 将time_t格式转换为tm结构体
	
	int year, month, day, hour, minute, second;// 定义时间的各个int临时变量。
	year = tm_->tm_year + 1900;                // 临时变量，年，由于tm结构体存储的是从1900年开始的时间，所以临时变量int为tm_year加上1900。
	month = tm_->tm_mon + 1;                   // 临时变量，月，由于tm结构体的月份存储范围为0-11，所以临时变量int为tm_mon加上1。
	day = tm_->tm_mday;
	hour = tm_->tm_hour;
	minute = tm_->tm_min;
	second = tm_->tm_sec;
 
	char s[20];                                // 定义总日期时间char*变量。
	sprintf(s, "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second);// 将年月日时分秒合并。
	std::string str(s);                       // 定义string变量，并将总日期时间char*变量作为构造函数的参数传入。
	return std::move(str);                    // 返回转换日期时间后的string变量。
 }
 
 
 int f(pid_t pid)
 {
	int fd;
	char buff[128];
	char *p;
	unsigned long uptime;
	struct timeval tv;
	static time_t boottime;
	time_t now = time(0);
 
	if ((fd = open("/proc/uptime", 0)) != -1)
	{
		if (read(fd, buff, sizeof(buff)) > 0)
		{
		  uptime = strtoul(buff, &p, 10);
		  gettimeofday(&tv, 0);
		  boottime = tv.tv_sec - uptime;
		}
		close(fd);
	}
 
 
	ifstream procFile;
	
	char stat[255];
	sprintf(stat, "/proc/%d/stat", pid);
	
	procFile.open(stat);
 
	char str[255];
	procFile.getline(str, 255);  // delim defaults to '\n'
 
 
	vector<string> tmp;
	istringstream iss(str);
	copy(istream_iterator<string>(iss),
		 istream_iterator<string>(),
		 back_inserter<vector<string> >(tmp));
	cout<<"now"<<now<<endl;
	cout<<"boottime"<<boottime<<endl;
	for(int i=0;i<tmp.size();i++)
	{
		cout<< i <<" : " <<tmp[i]<<endl;
	}
	
 
	cout<<"CLOCKS_PER_SEC"<<CLOCKS_PER_SEC<<endl;
	auto lstStr = tmp.at(21);
	cout<<lstStr<<endl;
	auto duration = (atof(tmp.at(21).c_str()))/HZ;//其实是100
	auto start_time = boottime + duration;
	auto startStr = time2string(start_time);
	
	printf("start: %d\n", start_time);
	
	cout<<"result:"<<startStr<<endl;
 }
 
 
 int main(int argc, char** argv)
 {
	 int pid = 1;
	 if(argc>1)
	 {
		 pid = atoi(argv[1]);
	 }
	 
	 auto t= f(pid);
	 
	 getchar();
	 return 0;
 }